package cn.tedu.rms.comment.controller;

import cn.tedu.rms.base.response.JsonResult;
import cn.tedu.rms.comment.pojo.dto.CommentSaveParam;
import cn.tedu.rms.comment.pojo.vo.CommentVO;
import cn.tedu.rms.comment.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "评论模块")
@RequestMapping("/v1/comment")
public class CommentController {
    @Autowired
    CommentService commentService;

    @ApiOperation(value = "查询我的评论")
    @GetMapping("/myComment")
    public JsonResult selectMyComment(Long userId){
        log.debug("查询我的评论，参数：{}",userId);
        List<CommentVO> list=commentService.selectMyComment(userId);
        return JsonResult.ok(list);
    }
    @ApiOperation(value = "保存 ‘新增或修改’评论")
    @PostMapping("/save")
    public JsonResult saveComment(CommentSaveParam commentSaveParam){
        log.debug("保存评论，参数：{}",commentSaveParam);
        commentService.saveComment(commentSaveParam);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除评论")
    @PostMapping("/deleteById/{id}")
    public JsonResult deleteCommentById(@PathVariable Long id){
        log.debug("删除评论，参数：{}",id);
        commentService.deleteCommentById(id);
        return JsonResult.ok();
    }
}
